<template>
  <div class="page" :style="{minHeight:docHeight}">
    <ELHeader></ELHeader>
    <div class="content-main clearfix">
      <LeftSideBar></LeftSideBar>
          <el-col :xs="17" :sm="18" :md="19" class="right-content clearfix">
            <ECharts :options="bar" eclass="echart-line" :resize="resize"></ECharts>
            <ECharts :options="polar" eclass="echart-line" :resize="resize"></ECharts>
            <ECharts :options="pie" eclass="echart-line" :resize="resize"></ECharts>
          </el-col>
    </div>
  </div>
</template>

<style lang="scss">

    .echarts {
        height: 300px;
    }

    .content-main{
      height: 0;
      min-height: 100%;
    }

    .right-content{
      padding-left: 20px;
      padding-top: 20px;
      padding-bottom: 100px;
      float: left;
    }

    .echart-line{
      width: 100%;
      height: 400px;
    }
</style>

<script>
import Header from 'components/Header'
import LeftSideBar from 'components/LeftSideBar'
import {Col} from 'element-ui'
import ECharts from 'components/ECharts'
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/bar'
import 'echarts/lib/chart/pie'
import 'echarts/lib/component/legend'


export default {
   data(){

        return {
            docHeight : window.innerHeight+'px',

            screenWidth: document.body.clientWidth,

            resize: false,

            polar: {
                width: '90%',

                title: {
                    text: '标题',
                    x: 'center'
                },

                grid: {
                    left: '0%',
                    right: '4%',
                    bottom: '8%',
                    containLabel: true
                },

                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['营销开拓'],
                    y: "bottom"
                },
                toolbox: {
                    show: true, //是否显示工具箱
                    feature: {
                        mark: { show: true },
                        dataView: { show: true, readOnly: false },
                        magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
                        restore: { show: true },
                        saveAsImage: { show: true }
                    }
                },
                //calculable: true,    容易搞错的属性，折线图、柱状图是否叠加
                xAxis: [{
                    type: 'category',
                    boundaryGap: false,
                    data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
                }],
                yAxis: [{
                    type: 'value'
                }],
                series: [
                    {
                        name: '营销开拓',
                        type: 'line',
                        stack: '总量',
                        data: [120, 132, 101, 134, 90, 230, 210, 300, 600, 1800]
                    }
                ]
            },

            bar : {
              width: '100%',

              tooltip : {
                  trigger: 'axis',
                  axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                      type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                  }
              },
              legend: {
                  data:['直接访问','营销开拓','到访','儿保科','市场开拓','渠道营销开拓','渠道纯名单','线上开拓','线上']
              },
              grid: {
                  left: '0%',
                  right: '4%',
                  bottom: '3%',
                  width: '90%',
                  containLabel: true
              },

              xAxis : [
                  {
                      type : 'category',
                      data : ['周一','周二','周三','周四','周五','周六','周日']
                  }
              ],
              yAxis : [
                  {
                      type : 'value'
                  }
              ],
              series : [
                  {
                      name:'直接访问',
                      type:'bar',
                      data:[320, 332, 301, 334, 390, 330, 320]
                  },
                  {
                      name:'营销开拓',
                      type:'bar',
                      stack: '广告',
                      data:[120, 132, 101, 134, 90, 230, 210]
                  },
                  {
                      name:'到访',
                      type:'bar',
                      stack: '广告',
                      data:[220, 182, 191, 234, 290, 330, 310]
                  },
                  {
                      name:'儿保科',
                      type:'bar',
                      stack: '广告',
                      data:[150, 232, 201, 154, 190, 330, 410]
                  },
                  {
                      name:'市场开拓',
                      type:'bar',
                      data:[862, 1018, 964, 1026, 1679, 1600, 1570],
                      markLine : {
                          lineStyle: {
                              normal: {
                                  type: 'dashed'
                              }
                          },
                          data : [
                              [{type : 'min'}, {type : 'max'}]
                          ]
                      }
                  },
                  {
                      name:'渠道营销开拓',
                      type:'bar',
                      barWidth : 5,
                      stack: '市场开拓',
                      data:[620, 732, 701, 734, 1090, 1130, 1120]
                  },
                  {
                      name:'渠道纯名单',
                      type:'bar',
                      stack: '市场开拓',
                      data:[120, 132, 101, 134, 290, 230, 220]
                  },
                  {
                      name:'线上开拓',
                      type:'bar',
                      stack: '市场开拓',
                      data:[60, 72, 71, 74, 190, 130, 110]
                  },
                  {
                      name:'线上',
                      type:'bar',
                      stack: '市场开拓',
                      data:[62, 82, 91, 84, 109, 110, 120]
                  }
              ]
          },

          pie : {
              width: '100%',

              tooltip: {
                  trigger: 'item',
                  formatter: "{a} <br/>{b}: {c} ({d}%)"
              },
              legend: {
                  y:"bottom",
                  data:['市场活动','网络','市场开拓','营销开拓','到访','儿保科','渠道营销开拓','渠道纯名单','线上开拓','线上']
              },

              series: [
                  {
                      name:'访问来源',
                      type:'pie',
                      selectedMode: 'single',
                      radius: [0, '30%'],

                      label: {
                          normal: {
                              position: 'inner'
                          }
                      },
                      labelLine: {
                          normal: {
                              show: false
                          }
                      },
                      data:[
                          {value:335, name:'市场活动', selected:true},
                          {value:679, name:'网络'},
                          {value:1548, name:'市场开拓'}
                      ]
                  },
                  {
                      name:'访问来源',
                      type:'pie',
                      radius: ['40%', '55%'],

                      data:[
                          {value:335, name:'市场活动'},
                          {value:310, name:'营销开拓'},
                          {value:234, name:'到访'},
                          {value:135, name:'儿保科'},
                          {value:1048, name:'渠道营销开拓'},
                          {value:251, name:'渠道纯名单'},
                          {value:147, name:'线上开拓'},
                          {value:102, name:'线上'}
                      ]
                  }
              ]
          }
        }
  },

  watch: {

    screenWidth (val) {
        if (!this.timer) {
            this.screenWidth = val
            this.timer = true
            let that = this

            setTimeout(function () {
                that.resize = !that.resize
                that.timer = false
            }, 400)
        }
      }

  },

  mounted: function(){

      const that = this
          window.onresize = () => {
            return (() => {
                window.screenWidth = document.body.clientWidth
                that.screenWidth = window.screenWidth
              })()
      }
  },

  components: {
    'ELHeader' : Header,
    'LeftSideBar' : LeftSideBar,
    'ECharts' : ECharts,
    'el-col' : Col
  }
}
</script>
